/**
 * @file trade/Home.js
 *  实例操作流水
 * @author
 */

import React, {Component, PropTypes} from 'react';
import {connect} from 'dva';
import {routerRedux, Link, withRouter} from 'dva/router';
import {
	Table,
	Card,
  Collapse
} from 'antd';
import Tabtitle from '../../../components/common/TabTitle';
// import styles from './home.less';

const Panel = Collapse.Panel;
const Realtime = ({
	dispatch,
	insrealtime,
	location
}) => {
	if (insrealtime.status) {
		const {tradeList,prolossList,comList,holdList, state} = insrealtime;
		console.log('insrealtime>>>>', insrealtime,);
		const columns_trade = [
			{
				title: '基金号',
				dataIndex: 'fundId',
				key: 'fundId',
			}, {
				title: '组合号',
				dataIndex: 'combiNo',
				key: 'combiNo'
			}, {
				title: '组合名称',
				dataIndex: 'combiName',
				key: 'combiName'
			}, {
				title: '实例号',
				dataIndex: 'instanceId',
				key: 'instanceId',
			}, {
				title: '证券名称',
				dataIndex: 'stockCode',
				key: 'stockCode',
			}, {
				title: '交易类型',
				dataIndex: 'tradeDirection',
				key: 'tradeDirection'
			}, {
				title: '平均基差',
				dataIndex: 'avgBasisSpread',
				key: 'avgBasisSpread'
			}, {
				title: '数量',
				dataIndex: 'dealAmount',
				key: 'dealAmount'
			}, {
				title: '汇总类型',
				dataIndex: 'tradeTypeText',
				key: 'tradeTypeText'
			},
		];
    const columns_pl = [
			{
				title: '基金号',
				dataIndex: 'fundId',
				key: 'fundId',
			}, {
				title: '组合号',
				dataIndex: 'combiNo',
				key: 'combiNo'
			}, {
				title: '组合名称',
				dataIndex: 'combiName',
				key: 'combiName'
			}, {
				title: '实例号',
				dataIndex: 'instanceId',
				key: 'instanceId',
			}, {
				title: '实例总盈亏',
				dataIndex: 'totalProfit',
				key: 'totalProfit',
			}, {
				title: '基差总盈亏',
				dataIndex: 'basisSpreadProfit',
				key: 'basisSpreadProfit'
			}, {
				title: '贝塔盈亏',
				dataIndex: 'betaProfit',
				key: 'betaProfit'
			}, {
				title: '成本',
				dataIndex: 'cost',
				key: 'cost'
			}, {
				title: '阿尔法盈亏',
				dataIndex: 'alphaProfit',
				key: 'alphaProfit'
			}, {
				title: '阿尔法盈亏+成本',
				dataIndex: 'alphaAndCost',
				key: 'alphaAndCost'
			}, {
				title: '空头市值',
				dataIndex: 'totalShortValue',
				key: 'totalShortValue'
			},
      {
       title: '多头市值',
       dataIndex: 'totalLongValue',
       key: 'totalLongValue'
     },
   ];
    const columns_com = [
			{
				title: '基金号',
				dataIndex: 'fundId',
				key: 'fundId',
			}, {
				title: '组合号',
				dataIndex: 'combiNo',
				key: 'combiNo'
			}, {
				title: '组合名称',
				dataIndex: 'combiName',
				key: 'combiName'
			}, {
				title: '组合总盈亏',
				dataIndex: 'totalProfit',
				key: 'totalProfit',
			}, {
				title: '基差总盈亏',
				dataIndex: 'basisSpreadProfit',
				key: 'basisSpreadProfit'
			}, {
				title: '贝塔盈亏',
				dataIndex: 'betaProfit',
				key: 'betaProfit'
			}, {
				title: '成本',
				dataIndex: 'cost',
				key: 'cost'
			}, {
				title: '阿尔法盈亏',
				dataIndex: 'alphaProfit',
				key: 'alphaProfit'
			}, {
				title: '阿尔法盈亏+成本',
				dataIndex: 'alphaAndCost',
				key: 'alphaAndCost'
			}, {
				title: '空头市值',
				dataIndex: 'totalShortValue',
				key: 'totalShortValue'
			},
      {
       title: '多头市值',
       dataIndex: 'totalLongValue',
       key: 'totalLongValue'
     },
   ];
    const columns_hold = [
      {
        title: '基金号',
        dataIndex: 'fundId',
        key: 'fundId',
      },
      {
        title: '组合号',
        dataIndex: 'combiNo',
        key: 'combiNo',
      },
      {
        title: '组合名称',
        dataIndex: 'combiName',
        key: 'combiName',
      },
      {
        title: '实例号',
        dataIndex: 'instanceId',
        key: 'instanceId',
      },
      {
        title: '证券名称',
        dataIndex: 'stockCode',
        key: 'stockCode',
      },
      {
        title: '多空',
        dataIndex: 'contractType',
        key: 'contractType',
      },
      {
        title: '持仓数',
        dataIndex: 'endHoldingAmount',
        key: 'endHoldingAmount',
      },
      {
        title: '开仓总数',
        dataIndex: 'totalOpenAmount',
        key: 'totalOpenAmount',
      },
      {
        title: '开仓基差',
        dataIndex: 'openBasisSpread',
        key: 'openBasisSpread',
      },
      {
        title: '平仓总数',
        dataIndex: 'totalCloseAmount',
        key: 'totalCloseAmount',
      },
      {
        title: '平仓基差',
        dataIndex: 'closeBasisSpread',
        key: 'closeBasisSpread',
      },
      {
        title: '收盘基差',
        dataIndex: 'eodBasisSpread',
        key: 'eodBasisSpread',
      },
      {
        title: '基差盈亏',
        dataIndex: 'basisSpreadProfit',
        key: 'basisSpreadProfit',
      },
    ];

		return (
			<div>
				<Tabtitle value={'实时刷新'}/>
				<div className="page-real-home content-inner">
          <h1>尊敬的客户，经分析您的套保账户盈利状况如下：</h1>
          <Collapse defaultActiveKey={['1','2','3','4']}>
            <Panel header="实例操作流水" key="1">
              <Table columns={columns_trade} dataSource={tradeList} record={record => `${record.fundId}-${record.combiNo}-${record.combiName}-${record.instanceId}-${record.tradeDirection}-${record.tradeTypeText}-${record.stockCode}-${record.dealAmount}-${record.avgBasisSpread}`}/>
            </Panel>
            <Panel header="实例盈亏" key="2">
              <Table columns={columns_pl} dataSource={prolossList} record={record => `${record.fundId}-${record.combiNo}-${record.combiName}-${record.instanceId}-${record.totalProfit}-${record.basisSpreadProfit}-${record.cost}-${record.alphaProfit}-${record.alphaAndCost}-${record.totalShortValue}-${record.totalLongValue}`}/>
            </Panel>
            <Panel header="组合盈亏" key="3">
              <Table columns={columns_com} dataSource={comList} record={record => `${record.fundId}-${record.combiNo}-${record.combiName}-${record.totalProfit}-${record.totalProfit}-${record.basisSpreadProfit}-${record.cost}-${record.alphaProfit}-${record.alphaAndCost}-${record.totalShortValue}-${record.totalLongValue}`}/>
            </Panel>
            <Panel header="实例持仓" key="4">
              <Table columns={columns_hold} dataSource={holdList} record={record => `${record.fundId}-${record.combiNo}-${record.combiName}-${record.instanceId}-${record.stockCode}-${record.contractType}-${record.endHoldingAmount}-${record.totalOpenAmount}-${record.openBasisSpread}-${record.totalCloseAmount}-${record.closeBasisSpread}-${record.eodBasisSpread}-${record.basisSpreadProfit}`}/>
            </Panel>
          </Collapse>
        </div>
      </div>
		)
	} else {
		return null
	}
}

Realtime.propTypes = {}
export default connect(({insrealtime}) => ({insrealtime}))(Realtime)
